package com.ytt.service;

import com.ytt.bean.MyException;
import com.ytt.bean.dobean.User;
import com.ytt.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserServiceImpl implements UserService{
    @Autowired
    UserDao userDao;
    /**
     * 测试事物
     * @return
     */
    @Transactional
    @Override
    public User testShiWu() {
        userDao.getUser(1);
        userDao.getUser(2);
        User user=new User();
        user.setName("小红");
        user.setPassword("小红");
        userDao.addUser(user);
        if(user.getId()==0){
            throw new MyException("异常了吗？异常了");
        }

        User user2=new User();
        user2.setName("小红2");
        user2.setPassword("小红2");
        userDao.addUser(user2);
        return null;
    }
}
